#!/bin/bash
#
# kube+docker 安装脚本 2016-08-19 
#
cols=`tput cols`
test -z "$*" && \
	echo 'ERROR! kubedocker.sh 必要参数不能为空！参数要求: nodeIp1 nodeIp2...(以” “分割)' \
    && exit -1;

cd $(cd `dirname $0`; pwd)

for file in setup-master.sh addNode.sh install-goaccess.sh sshkeygen.sh setup-node.sh addRoute.sh doAddRoute.sh getPubKey.sh
do
	echo "test file $file .."
	test ! -f $file && echo "$file not found." && exit -1
done
#get registry ip
#sh getDockerRegistry.sh
#dockerRegistry=`cat /usr/local/etc/registry`
#if [[ -z "$dockerRegistry" ]]; then
#	echo "Error! dockerRegistry setup error."
#	sh printLine.sh 'x'
#	exit -1;
#fi

cp registry.crt /var/nas/

# 执行master安装脚本
sh setup-master.sh
#sh install-goaccess.sh

if [ -d "../master" ]; then
	echo "copy tools to /usr/local/bin/"
	cp ../master/* /usr/local/bin/
	chmod +x /usr/local/bin/*
else
	echo "Error! master dir not found."
	sh printLine.sh 'x' 2
fi

# 执行node安装脚本
sh addNode.sh $*
kubectl get node
addedNodes=$(kubectl get node|grep -v 'NAME'|awk '{print $1}')

if [[ -z "$addedNodes" ]]; then
	echo "no node registered."
	sh printLine.sh 'x'
	exit -1;
fi
# dns
sh install-services.sh



